<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<%@ taglib prefix ="s" uri="/struts-tags"%>
<!DOCTYPE html>

<html lang="zh-Hans">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<head>
<%@ include file="/common/common-css.jsp"%>
</head>
<style>
   .load_bg{background:#000;opacity:0.1;left:0px;top:0px;position:fixed;height:100%;width:100%;overflow:hidden;z-index:10000;}
   .load_img{left:50%;top:180px;position:fixed;height:50px;overflow:hidden;z-index:20000;}
</style>   
<body class="no-skin">

<div  class="load_bg" style="display:none;" ></div>
<img src="http://img.xmiles.cn/commentloading.gif" class="load_img" style="display:none"/>


<form id="queryForm">
	 <div class="widget-main">
		 <div class="row">
		
				 <div class="form-group col-sm-12 col-xs-12">
					<label class="col-sm-2 col-xs-2 control-label text-right"  for="appLink">app内部链接:</label>
					<div class="input-group col-sm-10 col-xs-10">
						<input class="form-control" type="url" name="appLink" id="appLink" value="${paramsMap.appLink}"/>
					</div>
				 </div>
				 
				  <div class="form-group col-sm-12 col-xs-12">
					<label class="col-sm-2 col-xs-2 control-label text-right"  for="outerLink">app外部链接:</label>
					<div class="input-group col-sm-10 col-xs-10">
						<input class="form-control" type="text" name="outerLink" id="outerLink" value="${paramsMap.outerLink}"/>
					</div>
				 </div>
				 

			 </div>
		 </div>
		 <div class="text-center">
		 	  <button class="btn  btn-success no-border" name="btn-save" id="btn-save">
						<i class="ace-icon fa fa-floppy-o bigger-160"></i> 添加
				</button>
		 </div>
	 </div>	
</form>
<%@ include file="/common/common-js.jsp" %>
<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery.form.js"></script>
<script>      
		function getQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
 			var r = window.location.search.substr(1).match(reg);
			if (r != null) return decodeURI(r[2]); return null;
	 	};
	 	
		jQuery(function() {
			
			$("#btn-save").bind("click",function() {
				
				var appLink = $('#appLink').val();
				var outerLink = $('#outerLink').val();

                var strRegex = "^((https|http)?://)";

                var regu ="^((https|http)?://)";
                var re = new RegExp(regu);
                if(appLink != null && appLink != "" && !re.test(appLink)){
                    alert("请输入正确的app内部链接");
                    return;
				}

				if(outerLink != null && outerLink != "" && !re.test(outerLink)){
                    alert("请输入正确的外部链接");
                    return;
				}

                $.ajax({
                    "type": "POST",
                    "dataType": 'json',
                    "url": "${ctx}/spread/updateRedirectLinkRequest.action",
                    "data":{"appLink": appLink, "outerLink": outerLink},
                    "beforeSend": function(){
                        $(".load_bg,.load_img").show();
                    },
                    "success": function(resp){
                        console.log(resp);
                        if(resp.result.status == 1){
                            alert(resp.result.msg);
                            parent.parent['__extdialog_active'].dialog('close');
                        }
                    },
                    "error": function(XMLHttpRequest, textStatus, errorThrown) {
                        alert(textStatus);
                    },
                    "complete": function(){
                        $(".load_bg,.load_img").hide();
                    }
                });

				return false;
			});

	  });
	</script>
</body>
</html>